In [1]:
require 'pry'
require 'awesome_print'
require 'nyaplot'
require 'linear_regression_trend'
Out[1]:
In [2]:
y = [1,2,3,6,10,11,12,12,12,12,15,18,18,16,16,15,14,11,9,9,7,4,2,1,1]
x = (1..y.size).to_a.map { |n| n.to_s }
t = LinearRegressionTrend::Calculator.new(y)
IRuby.display IRuby.table([['Slope', 'Intercept'], [t.slope, t.intercept]])
In [3]:
chart = Nyaplot::Plot.new
chart.add(:bar, x, y)
chart.show
In [4]:
chart = Nyaplot::Plot.new
chart.add(:bar, x, t.trend)
chart.show
In [13]:
y = [1,2,3,0,10,18,18,18,1,1,1,1,0.5,0.5,0.5,0.5,05,0.25,0.25,0.1,0.1,0,0,0,0]
x = (1..y.size).to_a.map { |n| n.to_s }
t = LinearRegressionTrend::Calculator.new(y, non_negative: true)
IRuby.display IRuby.table([['Slope', 'Intercept', 'Conclusion'], [t.slope, t.intercept, t.trend.last]])
In [12]:
chart = Nyaplot::Plot.new
chart.add(:bar, x, t.trend)
chart.show
In [10]:
IRuby.display IRuby.table([(1..y.size).to_a.reverse, t.trend.reverse])